package com.tianhui.consignortwofei.mvp.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fgs.common.interf.ISelectItemValue;
import com.tianhui.consignortwofei.R;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fgs
 * @date 2021/4/22
 * @description
 **/
public class SelectRightTimeAdapter extends RecyclerArrayAdapter<ISelectItemValue> {
    private int selectPosition;

    public SelectRightTimeAdapter(Context context) {
        super(context);
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
        notifyDataSetChanged();
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new SelectLeftTimeViewHolder(parent, R.layout.item_right_select_time);
    }


    public class SelectLeftTimeViewHolder extends BaseViewHolder<ISelectItemValue> {

        private TextView timeTextView;


        public SelectLeftTimeViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            timeTextView = getView(R.id.item_right_select_time_timeTextView);
        }

        @Override
        public void setData(ISelectItemValue data) {
            super.setData(data);
            timeTextView.setText(data.getSelectItemText());
            timeTextView.setSelected(selectPosition == getAdapterPosition());
        }
    }

    public ISelectItemValue getSelectTime() {
        if (getAllData() != null && selectPosition < getCount()) {
            return getAllData().get(selectPosition);
        } else {
            return null;
        }
    }
}
